<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>组件添加v-model - {{ msg }}</h2>
      <!-- <input type="text" :value="str" @input="handleInput" />
      <p>{{ str }}</p> -->

      <!-- <child :value="msg" @input="getNewMsg"></child> -->
      <child v-model="msg"></child>
    </div>

    <script src="./Vue.js"></script>
    <script>
      const Child = {
        props: {
          value: String,
        },
        template: `
          <div>child子组件 - <input type="text" :value="value" @input="handleInput" /></div>
        `,
        methods: {
          handleInput(e) {
            this.$emit("input", e.target.value);
          },
        },
      };

      new Vue({
        el: "#app",
        // data: {
        //   str: "abc",
        // },
        // methods: {
        //   handleInput(e) {
        //     this.str = e.target.value;
        //   },
        // },
        components: {
          Child,
        },
        data() {
          return {
            msg: "aa",
          };
        },
        methods: {
          // getNewMsg(v) {
          //   this.msg = v;
          // },
        },
      });
    </script>
  </body>
</html>
